<template>

    <el-form label-width="120px" label-position="left">

        <el-form-item label="当前密码">
            <el-input v-model="current_password" type="password"></el-input>
        </el-form-item>
        <el-form-item label="新密码">
            <el-input v-model="new_password" type="password"></el-input>
        </el-form-item>

        <el-form-item label="重复新密码">
            <el-input v-model="new_password_reset" type="password"></el-input>
        </el-form-item>

        <el-form-item label="">

            <el-button type="primary" @click="changePassword"> 提交 </el-button>
        </el-form-item>
    </el-form>
</template>  
<script lang="ts" setup>    

import { ref, reactive, provide } from 'vue';
import axios from 'axios';
import { ElMessage } from 'element-plus';
const VITE_URL = window.VITE_URL;
const current_password = ref('')
const new_password = ref('')
const new_password_reset = ref('')

const changePassword = () => {

    const url: string = VITE_URL + '/admin.user/changepwd'
    const data = {
        current_password:current_password.value,
        new_password:new_password.value,
    }

    if( new_password_reset.value != new_password.value ){

        ElMessage({
            message: '新密码输入不一致',
            duration: 1000,
            type: 'error',
        })
        return;
    }

    axios.post( url, data ).then( res => {

        if( !res.data.code ){
            current_password.value = '';
            new_password.value = '';
            new_password_reset.value = '';
        }

        ElMessage({
            message: res.data.code == 0 ? '修改成功' : res.data.message,
            duration: 1000,
            type: res.data.code == 0 ? 'success' : 'error',
        })
    })

}

</script>  